<template>
  <div class="page-content">
    <h2 id="7">实验报告上传接口</h2>
    <p>平台登录用户进入学校实验平台完成实验后，通过实验报告上传接口将学校实验平台生成的实验报告回传到平台。</p>
    <p><strong>注意事项</strong></p>
    <p>1、如果有实验报告，则先调用数据回传接口，然后再调用实验报告上传接口。</p>
    <p><strong>接口调用请求说明</strong></p>
    <p>http请求方式：POST/GET <a href="javascript:">{{ addr }}/oauth/api/v1/attachment_upload?access_token=ACCESS_TOKEN&amp;appid=APPID&amp;originId=ORIGINID&amp;filename=FILENAME&amp;title=TITLE&amp;remarks=REMARKS</a></p>
    <p><strong>参数说明</strong></p>
    <div class="table-ctn">
      <table>
        <thead>
          <tr>
            <th width="100">参数</th>
            <th>说明</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td>access_token</td>
            <td>接口调用令牌</td>
          </tr>
          <tr>
            <td>appid</td>
            <td>由“平台”分配给实验教学项目的编号</td>
          </tr>
          <tr>
            <td>originId</td>
            <td>实验平台实验记录ID</td>
          </tr>
          <tr>
            <td>filename</td>
            <td>上传文件的名称，需要带文件扩展名，如：实验报告.pdf，请使用 urlEncode 对FILENAME进行处理</td>
          </tr>
          <tr>
            <td>title</td>
            <td>实验报告名称，请使用 urlEncode 对TITLE进行处理</td>
          </tr>
          <tr>
            <td>remarks</td>
            <td>备注，请使用 urlEncode 对remarks进行处理</td>
          </tr>
        </tbody>
      </table>
    </div>
    <p><strong>调用URL示例</strong></p>
    <p>curl -X POST --data '文件内容' '{{ addr }}/oauth/api/v1/attachment_upload?<span style="color: red">access_token</span>=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJtc2ciOiLosIPnlKjmiJDlip_vvIzov5Tlm57miYDpnIDmlbDmja4iLCJjb2RlIjowLCJjcmVhdGVfdGltZSI6MTcxMTEwMzIyOTEyMiwiY3JlYXRlX3RpbWVfZGlzcGxheSI6IjIwMjQtMDMtMjIgMTg6Mjc6MDkiLCJ1c2VyX25hbWUiOiIxNzAxODA4MTY5NzkzMTM4NjkwIiwiYXV0aG9yaXRpZXMiOlsiQURNSU4iXSwiY2xpZW50X2lkIjoiMTY4MTYwMDIyMjc0ODI0MTkyOSIsImRpcyI6IjE3MDE4MDgxNjk3OTMxMzg2OTAiLCJzY29wZSI6WyJjYWxsYmFjazpzY29yZSJdLCJleHBpcmVzX3RpbWVfZGlzcGxheSI6IjIwMjQtMDMtMjMgMTg6Mjc6MDgiLCJ1biI6IjE3MDE4MDgxNjk3OTMxMzg2OTAiLCJleHAiOjE3MTExODk2MjksImp0aSI6ImE1N2FiOTljLTZlZDMtNGI5My1hOGEzLTA3NzQ2NDM0ZmZlOCIsImV4cGlyZXNfdGltZSI6MTcxMTE4OTYyODEyMn0.rnRo5Z0D4R2p6jd57Ld29hAOegDtddKA4Z4sp4C7kD8&amp;<span style="color: red">appid</span>=1681600222748241929&amp;<span style="color: red">originId</span>=1112&amp;<span style="color: red">filename</span>=%E5%AE%9E%E9%AA%8C%E6%8A%A5%E5%91%8A.txt&amp;title=%E6%B5%8B%E8%AF%95%E5%AE%9E%E9%AA%8C%E6%8A%A5%E5%91%8A'</p>
    <p><strong>返回结果</strong></p>
    <p>正确时的返回JSON数据包如下：</p>
    <pre><code>{
    <span class="key">"code":</span> <span class="number">0</span>,
    <span class="key">"id":</span> <span class="string">"1"</span>
}</code></pre>
    <p>错误时的返回JSON数据包如下（示例为参数错误）：</p>
    <pre><code>{
    <span class="key">"code":</span> <span class="number">1</span>,
    <span class="key">"msg":</span> <span class="string">"参数错误"</span>
}</code></pre>
    <p><strong>返回码说明：</strong></p>
    <div class="table-ctn">
      <table>
        <thead>
          <tr>
            <th>返回码</th>
            <th>说明</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td>0</td>
            <td>调用成功</td>
          </tr>
          <tr>
            <td>1</td>
            <td>参数错误：access_token缺失/originId缺失/appid缺失/filename缺失/filename未指定扩展名</td>
          </tr>
          <tr>
            <td>2</td>
            <td>非法操作：密钥错误</td>
          </tr>
          <tr>
            <td>3</td>
            <td>access_token超时</td>
          </tr>
          <tr>
            <td>4</td>
            <td>授权错误：未知分配APPID/分配APPID不匹配</td>
          </tr>
          <tr>
            <td>5</td>
            <td>非法操作：不正确的access_token</td>
          </tr>
          <tr>
            <td>6</td>
            <td>非法操作：重复上传实验报告</td>
          </tr>
          <tr>
            <td>7</td>
            <td>非法操作：originId数据不存在</td>
          </tr>
          <tr>
            <td>8</td>
            <td>数据错误：未传输数据/数据大于5Mb</td>
          </tr>
          <tr>
            <td>10</td>
            <td>文件上传失败，请重试</td></tr>
          <tr>
            <td>11</td>
            <td>非法操作：originId 关联到多条实验成绩信息，无法上传</td>
          </tr>
          <tr>
            <td>其他值</td>
            <td>非法请求或系统错误</td>
          </tr>
        </tbody>
      </table>
    </div>
    <p />
    <p><strong>Python示例</strong></p>
    <pre><code>import os<br>from urllib.parse import quote, unquote<br><br>def attachment_upload():<br>    APPID = '1681600222748241929'<br>    ORIID = '1112'<br>    API_PATH = '{{ addr }}'<br><br>    # 此处是使用上一步获取到的ACCESS_TOKEN原文<br>    ACCESS_TOKEN = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJtc2ciOiLosIPnlKjmiJDlip_vvIzov5Tlm57miYDpnIDmlbDmja4iLCJjb2RlIjowLCJjcmVhdGVfdGltZSI6MTcxMTEwMzIyOTEyMiwiY3JlYXRlX3RpbWVfZGlzcGxheSI6IjIwMjQtMDMtMjIgMTg6Mjc6MDkiLCJ1c2VyX25hbWUiOiIxNzAxODA4MTY5NzkzMTM4NjkwIiwiYXV0aG9yaXRpZXMiOlsiQURNSU4iXSwiY2xpZW50X2lkIjoiMTY4MTYwMDIyMjc0ODI0MTkyOSIsImRpcyI6IjE3MDE4MDgxNjk3OTMxMzg2OTAiLCJzY29wZSI6WyJjYWxsYmFjazpzY29yZSJdLCJleHBpcmVzX3RpbWVfZGlzcGxheSI6IjIwMjQtMDMtMjMgMTg6Mjc6MDgiLCJ1biI6IjE3MDE4MDgxNjk3OTMxMzg2OTAiLCJleHAiOjE3MTExODk2MjksImp0aSI6ImE1N2FiOTljLTZlZDMtNGI5My1hOGEzLTA3NzQ2NDM0ZmZlOCIsImV4cGlyZXNfdGltZSI6MTcxMTE4OTYyODEyMn0.rnRo5Z0D4R2p6jd57Ld29hAOegDtddKA4Z4sp4C7kD8'<br>    FILE_NAME = 'test_report_file.docx'<br>    TITLE = '我的实验报告'<br><br>    f = open('report.txt', encoding='utf-8')<br>    content = f.read()<br>    f.close()<br><br>    # 此处是在linux中使用linux命令访问url，需要进行url编码<br>     upload_cmd = "curl -X POST --data '" + content + "' '" + API_PATH + "/oauth/api/v1/attachment_upload?access_token=" + quote(ACCESS_TOKEN) + "&amp;appid=" + APPID + "&amp;originId=" + ORIID + "&amp;filename=" + quote(FILE_NAME) + "&amp;title=" + quote(TITLE) + "'"<br>    print(upload_cmd)<br>    os.system(upload_cmd)<br><br><br>if __name__ == '__main__':<br>    attachment_upload()<br></code></pre><p><strong>Python示例运行结果</strong></p><p /><pre>{"code":0,"id":"2262"}</pre>
    <p />
    <p><strong>特别说明</strong></p>
    <p>1.接口支持前端语言Javascript使用。<a href="javascript:;" @click="downloadApi">《jquery 调用示例》</a></p>
    <p>2.实验报告上传若提示参数错误，请根据接口文档实验报告上传接口，检查参数是否存在，以及是否符合规范，核对文件仔细检查参数问题。</p>
  </div>
</template>
<script>
export default {
  data() {
    return {
      addr: ''
    }
  },
  mounted() {
    if (process.client) {
      this.addr = window.location.protocol + '//' + window.location.hostname + ':8180'
    }
  },
  methods: {
    downloadApi() {
      window.open(this.addr + '/jquery-api.html', '_blank')
      return false
    }
  }
}
</script>
